//---------------------------------------------------------------------
// Authors: jachymko
//
// Description: Type name tab expansion
//
// Creation Date: Jan 8, 2007
//
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

using Pscx.Commands.TabExpansion.Caches;

namespace Pscx.Commands.TabExpansion.Handlers
{
    class TypeNameHandler : TabExpansionHandler
    {
        public TypeNameHandler(GetTabExpansionCommand command)
            : base(command)
        {

        }

        public override void TryExpand(string line, string word)
        {
            Match m = _patternRemoveBraces.Match(word);

            if (m.Success)
            {
                WriteExpansions(m.Groups["TypeName"].Value);
                return;
            }

            m = _pattern.Match(word);
            if (m.Success)
            {
                WriteExpansions(TypeNameCache.Instance.Expand(m.Groups["TypeName"].Value));
            }
        }

        static readonly Regex _patternRemoveBraces = new Regex(@"(?x)
            \[ (?<TypeName> [^\]]* ) \]=");

        static readonly Regex _pattern = new Regex(@"(?x)
            \[ (?<TypeName> [^\]]*) $");
    }
}
